﻿using System;
using System.Linq;
using context;

namespace DataAccessLibrary.DAL
{
    public class AuthenDAO
    {
        private readonly BlueMDataContext _ctx;

        public AuthenDAO()
        {
            _ctx = new BlueMDataContext();
        }

        public string RoleGet(string userName, string password)
        {
            try
            {
                var query =
                    _ctx.Employees.Where(p => p.EmployeeAccount == userName && p.EmployeePassword == password).Select(
                        q => q.EmployeePosition);
                return query.FirstOrDefault();
            }
            catch (Exception)
            {
                return "";
            }
        }

        public bool UserCheck(string userName, string passWord, string position)
        {
            try
            {
                var query =
                    _ctx.Employees.Where(
                        p =>
                        p.EmployeeAccount == userName && p.EmployeePassword == passWord &&
                        p.EmployeePosition == position);
                return query.Any();
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}